home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14096 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: jaxnet.jaxnet.com!jax!garyg
  2. From: garyg@jax.jaxnet.com (Gary M. Greenberg)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Character string
  5. Date: 11 Apr 1996 22:23:12 GMT
  6. Organization: Southeast Network Services, Inc.
  7. Message-ID: <4kk0og$ifu@jaxnet.jaxnet.com>
  8. References: <4kil74$8i7@Tandem1.opennet.net.au>
  9. NNTP-Posting-Host: jax.jaxnet.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Kenneth H Smith (george@opennet.net.au) wrote:
  13. : How do I do a similar statement in C to the Pascal code:
  14.  
  15. : If Ch IN ['a','A'] THEN
  16. : I want to execute a piece of code when a particular character is entered
  17. : from the keyboard.
  18.  
  19. : I know I can use if (ch=='a') && (ch=='A') but was looking for something
  20. : a little more ellegant.
  21.                 ^^^ inelegant. Elegant ;-)
  22.  
  23. And, if you declare "char ch;" and then look for a character such that
  24.  
  25.     if(ch=='a' && ch=='A') ...
  26.  
  27. you'll not find it; ch won't be both simultaneously.
  28.  
  29. You want
  30.  
  31.     if(ch=='a' || ch=='A')
  32.         whatever;
  33.  
  34. I don't find it inelegant, but if you want a range of values,
  35. you are probably better off to either (a) use a switch statement, or
  36. (b) build a state machine.
  37.  
  38. : Thanks,
  39.  
  40. You're welcome.
  41.  
  42. : Ken Smith.
  43.  
  44. gary    /* the Sorcerer's Apprentice */ 
  45.     Contribute to the Randal Schwartz Legal Defense Fund
  46.        Get FREE ANSI C E-Mail Management Source Code     
  47.      Visit: http://jax.jaxnet.com/~garyg/main_page.html
  48.